// pages/person/person.js
Page({

  /**
   * 页面的初始数据
   */
  data: {
    id:"",
    userInfo: {},
    message: "",
    concern:'',
    num: {},
    hasUserInfo: true,
    canIUseGetUserProfile: false,
    show: false,
    max: 100, //限制最大输入字符数
    worksShow: true,
    loveShow: false,
    collectShow: false,
    likeData: [],
    collectData: [],
    myData: [],
    temp: "https://pic1.zhimg.com/v2-ab3dbd003b38d85a3af24b05caffde11_r.jpg?source=1940ef5c",
  },
// navi(e){
//   console.log(e.currentTarget.dataset.a)
//   let index=e.currentTarget.dataset.a
//   wx.navigateTo({
//     url: this.data.list[index].url+"?id="+index,
//   })
// },

concern(){
    let that=this
    wx.request({
      url: `http://localhost:1234/hu?type=3`,
      header: {
        'content-type': 'application/x-www-form-urlencoded'
      },
      data: {
        'userid':wx.getStorageSync('userid'),
        'concernid':that.data.id
      },
      method: 'POST',
      success: function (res) {
        let status = res.data.status;
        if (status == 200) {
          that.setData({
            concern:!that.data.concern
          })
        }
      },
      fail: function () {
        console.log("加载失败")
      }
    })
  
},
  // aaa() {
  //   wx.navigateBack({ delta: 1 })
  // },

  // 作品
  worksList: function () {
    console.log(this.data.id)
    wx.request({
      url: 'http://localhost:1234/person/works?userid=' + this.data.id,
      method: "GET",
      header: {
        'content-type': "application/json"
      },
      success: res => {
        console.log(res.data)
        this.setData({
          myData: res.data
        })
      },
      fail: error => {
        console.log(error);
      }
    })
    this.setData({
      worksShow: true,
      loveShow: false,
      collectShow: false
    })
  },
  // 喜欢
  loveList: function () {
    wx.request({
      url: 'http://localhost:1234/user/star/like?userid=' + this.data.id,
      method: "GET",
      header: {
        'content-type': "application/json"
      },
      success: res => {
        console.log(res.data)
        this.setData({
          worksShow: false,
          loveShow: true,
          collectShow: false,
          likeData: res.data
        })
      },
      fail: error => {
        console.log(error);
      }
    })
  },
  // 收藏
  collectList: function () {
    wx.request({
      url: 'http://localhost:1234/user/star/collect?userid=' + this.data.id,
      method: "GET",
      header: {
        'content-type': "application/json"
      },
      success: res => {
        console.log(res.data)

        this.setData({
          worksShow: false,
          loveShow: false,
          collectShow: true,
          collectData: res.data
        })
      },
      fail: error => {
        console.log(error);
      }
    })
  },

  onClickShow() {
    console.log('alalall')
    this.setData({ show: !this.data.show});
  },

  onClickHide() {
    this.setData({ show: false });
    console.log('aaaaaaaaaaaaaaaaaaaaaaaaaaaaaa')
  },


  noop() { },

  /**
   * 生命周期函数--监听页面加载
   */
  onLoad(options) {
    // 用户信息
    // console.log(options)
    this.setData({id:options.id})
   
  
  },


  /**
   * 生命周期函数--监听页面初次渲染完成
   */
  onReady() {

  },
  

  /**
   * 生命周期函数--监听页面显示
   */
  onShow() {
    let id=this.data.id
    console.log('a')
    let that=this
    wx.request({
      url: `http://localhost:1234/person?userid=${id}`,
      method: "GET",
      header: {
        'content-type': "application/json"
      },
      success: function (res) {
        console.log(res.data)
        that.setData({
          userInfo:res.data,
        })
      },
      fail: function () {
        console.log("加载失败")
      }
    })
    wx.request({
      url: `http://localhost:1234/fan?type=3`,
      header: {
        'content-type': 'application/x-www-form-urlencoded'
      },
      data:{
        'userid':wx.getStorageSync('userid'),
        'concernid':that.data.id
      },
      method: 'POST',
      success: function (res) {
        let status = res.data.status;
        // console.log(res.data.hu)
        if (status == 200) {
          that.setData({
            concern:JSON.parse(res.data.hu)
          })
        }
      },
      fail: function () {
        console.log("加载失败")
      }
    })
    this.worksList()
  },

  /**
   * 生命周期函数--监听页面隐藏
   */
  onHide() {

  },

  /**
   * 生命周期函数--监听页面卸载
   */
  onUnload() {

  },

  /**
   * 页面相关事件处理函数--监听用户下拉动作
   */
  onPullDownRefresh() {

  },

  /**
   * 页面上拉触底事件的处理函数
   */
  onReachBottom() {

  },

  /**
   * 用户点击右上角分享
   */
  onShareAppMessage() {

  }
})